﻿using System;
using System.Collections.Generic;
using System.Text;
using RaisingStudio.Data.Common;

namespace RaisingStudio.Data.Entities
{
    public class PointConverter : IDbTypeConverter
    {
        #region IDbTypeConvertermember

        public object ConvertFromDbType(object value)
        {
            string s = value as string;
            if (!string.IsNullOrEmpty(s))
            {
                string[] sa = s.Split(',');
                if ((sa != null) && (sa.Length == 3))
                {
                    int x = int.Parse(sa[0]);
                    int y = int.Parse(sa[1]);
                    int z = int.Parse(sa[2]);
                    return new Point(x, y, z);
                }
            }
            return null;
        }

        public object ConvertToDbType(object value)
        {
            if (value is Point)
            {
                Point point = (Point)value;
                return point.ToString();
            }
            return null;
        }

        #endregion
    }
}
